import React, { useMemo } from 'react';
import { Select } from 'antd';

import { INodeComponent } from './type';

export const NodeSelect: React.FC<INodeComponent> = (props) => {
  const data = useMemo(() => {
    return props?.data;
  }, [props?.data]);

  const onSelectChange = (value: any) => {
    if (value && props?.onChange) {
      props.onChange(value);
    }
  };
  return (
    <Select
      onChange={onSelectChange}
      placeholder={`请选择${data.labelName}`}
      value={props?.value ?? ''}
    >
      {data &&
        data?.optionList?.map((item: any, index: number) => {
          return (
            <Select.Option key={index} value={item?.value}>
              {item?.label}
            </Select.Option>
          );
        })}
    </Select>
  );
};
